<template>
    <div class="e-form">
        <div class="tabs">
            <div class="tabs-title">基本信息</div>
            <el-form ref="form" :model="formData.rests" label-width="200px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="标题：">
                            <el-input v-model="formData.rests.title" clearable></el-input>
                        </el-form-item>
                    </el-col>
                     <el-col :span="12">
                        <el-form-item label="填报日期：">
                            <el-date-picker
                                v-model="formData.rests.billDate"
                                type="date"
                                placeholder="选择日期"
                                value-format="yyyy-MM-dd"
                                format="yyyy 年 MM 月 dd 日"
                                :clearable="false"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                 <el-row>
                    <el-col :span="12">
                        <el-form-item label="类型：">
                            <el-select v-model="formData.rests.type"  >
                                <el-option :value="item.value" :label="item.label" v-for="item,index in otherType" :key="index" ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="formData.rests.type === '3'">
                        <el-form-item label="报停申请编号：">
                            <el-input v-model="formData.rests.billNo"  readonly>
                                <i slot="suffix" class="el-input__icon el-icon-document-copy" ></i>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="机构：">
                            <span>{{ formData.rests.orgName }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="状态：">
                            <span>{{ statusLable(formData.rests.state) }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item  label="概况：">
                            <el-input type="textarea" v-model="formData.rests.remarks" placeholder="请输入内容"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <div class="buttons">
            <el-button
                type="primary"
                size="small"
                class="btn-blue"
                @click="preserve"
                >保存</el-button
            >
            <el-button size="small" @click="handleClose">取消</el-button>
        </div>
    </div>
</template>

<script>
import request from '@/api/equip/dailyManagement.js'
import { mapState } from 'vuex'
import {  showSuccessPop } from '@/utils/common'
export default {
    data () {
        return {
            formData: {
                //基础信息
                'rests': {
                    'billDate': '',
                    'founderName': '',
                    'founderId': '',
                    'generalSituation': '',
                    'nullifyCreated': '',
                    'nullifyCreator': '',
                    'nullifyCreatorId': '',
                    'nullifyDesciption': '',
                    'nullifyReason': '',
                    'orgId': '',
                    'orgName': '',
                    'restsId': '',
                    'state': 0,
                    'title': '',
                    'type': '',
                    'workId': ''
                },
            },
            planNumberVisible: false,
            type: [
                {
                    value: '0',
                    label: '记录'
                },
                {
                    value: '1',
                    label: '其他申请'
                },
                {
                    value: '2',
                    label: '报停申请'
                },
                {
                    value: '3',
                    label: '报停启用申请'
                }
            ], //类型
        }
    },
    components: {
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo,
            otherType: state => state.equip.equipData.otherType, //其他类型
        }),
        statusLable () {
            return param=> {
                const state =  this.$store.state.equip.equipData.state//传财务单据状态
                const obj = state.find(x=>x.value === param)
                return obj.label
            }
        },
    },
    created () {
    },
    mounted () {
        this.userId = localStorage.getItem('userId')
        this.userName = localStorage.getItem('userName')
        const date = new Date()
        this.formData.rests.billDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
        this.formData.rests.founderName = this.userName
        this.formData.rests.founderId = this.userId
        this.formData.rests.orgName = this.userInfo.orgInfo.orgName
        this.formData.rests.orgId = this.userInfo.orgInfo.orgId
    },
    methods: {
        cellMouseEnter (row) {
            this.MouseEnterId = row.id
        },
        cellMouseLeave () {
            this.MouseEnterId = 0
        },
        //保存
        preserve () {
            request.otherAdd(this.formData).then(()=>{
                showSuccessPop('保存成功')
                this.$router.push('/otherList')
            })
        },
        //取消
        handleClose () {
            this.$router.go(-1)
        },
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}
</style>
